package com.brillilab.service.core.experiments.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.brillilab.dao.mapper.experiments.ExperimentGroupMapper;
import com.brillilab.dao.mapper.experiments.ExperimentPhaseMapper;
import com.brillilab.dao.mapper.experiments.ExperimentStepMapper;
import com.brillilab.dao.mapper.experiments.ExperimentTroubleShootingMapper;
import com.brillilab.domain.po.experiments.ExperimentGroup;
import com.brillilab.domain.po.experiments.ExperimentPhase;
import com.brillilab.domain.po.experiments.ExperimentStep;
import com.brillilab.domain.po.experiments.ExperimentTroubleShooting;
import com.brillilab.domain.vo.experiments.ExperimentStepSimple;
import com.brillilab.domain.vo.kit.KitInfoListVo;
import com.brillilab.service.core.experiments.IExperimentTroubleShootingService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 实验trouble shooting 服务实现类
 * </p>
 *
 * @author WuMenghao
 * @since 2019-09-05
 */
@Service
@Transactional
public class ExperimentTroubleShootingServiceImpl implements IExperimentTroubleShootingService {

    @Resource
    private ExperimentTroubleShootingMapper experimentTroubleShootingMapper;
    @Resource
    private ExperimentGroupMapper experimentGroupMapper;
    @Resource
    private ExperimentPhaseMapper experimentPhaseMapper;
    @Resource
    private ExperimentStepMapper experimentStepMapper;

    @Override
    public ExperimentTroubleShooting insert(ExperimentTroubleShooting entity) {
        int b = experimentTroubleShootingMapper.insert(entity);
        Assert.isTrue(b==1, "添加失败！");
        return entity;
    }

    @Override
    public ExperimentTroubleShooting update(ExperimentTroubleShooting entity) {
        int b = experimentTroubleShootingMapper.updateById(entity);
        Assert.isTrue(b==1, "编辑失败！");
        return entity;
    }

    @Override
    public List<ExperimentTroubleShooting> selectByExperimentId(Long experimentId) {
        List<ExperimentTroubleShooting> troubleShootings = experimentTroubleShootingMapper
                .selectList(new LambdaQueryWrapper<ExperimentTroubleShooting>()
                .eq(ExperimentTroubleShooting::getExperimentId,experimentId));
        return troubleShootings;
    }

    @Override
    public List<ExperimentPhase> selectExperimentPhase(Long experimentId) {
        List<ExperimentPhase> phaseList = experimentPhaseMapper.selectList(new LambdaQueryWrapper<ExperimentPhase>()
                .eq(ExperimentPhase::getExperimentId, experimentId));
        return phaseList;
    }

    @Override
    public List<ExperimentStep> selectExperimentStep(Long experimentId) {
        List<ExperimentStep> stepList = experimentStepMapper.selectList(new LambdaQueryWrapper<ExperimentStep>()
                .eq(ExperimentStep::getExperimentId, experimentId));
        return stepList;
    }

    @Override
    public List<KitInfoListVo> selectExperimentReagent(Long experimentId) {
        return experimentTroubleShootingMapper.selectExperimentReagent(experimentId);
    }

    @Override
    public List<ExperimentGroup> selectExperimentGroupList(Long experimentId) {
        List<ExperimentGroup> experimentGroups = experimentGroupMapper.selectList(new LambdaQueryWrapper<ExperimentGroup>()
                .eq(ExperimentGroup::getExperimentId,experimentId));
        return experimentGroups;
    }

    @Override
    public int deleteByExperimentId(Long experimentId) {
        int delTotal = experimentTroubleShootingMapper.delete(new LambdaQueryWrapper<ExperimentTroubleShooting>()
                .eq(ExperimentTroubleShooting::getExperimentId,experimentId ));
        return delTotal;
    }

    @Override
    public List<Long> selectIds(Long experimentId) {
        List<Long> ids = experimentTroubleShootingMapper.selectIdsByExperimentId(experimentId);
        return ids;
    }

    @Override
    public int deleteBatchById(List<Long> ids) {
        int deleteTotal = experimentTroubleShootingMapper.deleteBatchIds(ids);
        return deleteTotal;
    }
}
